package org.softmed.rest.admin.file;

import javax.swing.tree.DefaultMutableTreeNode;

import org.softmed.filehandling.FileUtil;

public class CustomFileNode extends DefaultMutableTreeNode {

	String name;
	String dirPath;
	String fullPath;

	public CustomFileNode(String string) {
		super(string);
		setFullPath(string);
	}

	public void setFullPath(String string) {
		fullPath = string;
		FileUtil util = new FileUtil();
		fullPath = util.fixPath(fullPath);

		int index = fullPath.lastIndexOf('/');

		if (index >= 0) {
			// String filePath = util.fixPath(fullPath.substring(index));
			name = fullPath.substring(index + 1);
			dirPath = fullPath.substring(0, index + 1);
		} else {
			name = fullPath;
			dirPath = "/";
		}
		setUserObject(name);
	}

	public String getName() {
		return name;
	}

	public String getDirPath() {
		return dirPath;
	}

	public String getFullPath() {
		return fullPath;
	}

	public void setDirPath(String dirPath) {
		this.dirPath = dirPath;
		if (dirPath.endsWith("/"))
			this.fullPath = dirPath + name;
		else
			this.fullPath = dirPath + "/" + name;
	}

}
